package com.education.springbootdemo.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;

//RestConstroller 是 Constroller 但是是返回ResponseBody

@Controller
public class IndexController {

    //MVC
    @RequestMapping("/index")
    @ResponseBody
    public String index() {

        // Model 是接口

//        ModelAndView mav = new ModelAndView("index");
//        mav.addObject("name","hyx");
        return "index";
    }

    @RequestMapping("/system")
    public String sys() {
        return "mav";
    }


    //实现一个服务端渲染的星期列表
    // 引入freemarker视图解析器
    // Model 参数设置 todolist = ["星期一","星期二","星期三",,"星期四","星期五","星期六","星期日"]
    // View 值是 week

    @RequestMapping("/week")
    public ModelAndView week() {
        ModelAndView mav = new ModelAndView("week");
        ArrayList<String> list = new ArrayList<String>();
        list.add("星期一");
        list.add("星期二");
        list.add("星期三");
        list.add("星期四");
        list.add("星期五");
        list.add("星期六");
        list.add("星期日");
        mav.addObject("weeks",list);
        return mav;
    }



}
